<?php 
require_once 'init.php';
require_once 'ckLogin.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
$db = new dbConn();

$act = $_GET['act']?$_GET['act']:''; 
//提交处理
if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
	$comments = $_POST['comments'];
	$str = str_replace(array("\r\n", "\n", "\r"), '|||', ($comments));
	$comment_arry = explode("|||", $str);
// 	if (count($comment_arry)>5) {
// 		$error = 1;//错误提醒，由于需要匹配，故不能超过5条
// 	}
	if ($act=='postshenhe') {
	    $cate_i = implode($_POST['cates'], ',');
		//获取所有
    	$db->sql = "SELECT id,comment FROM `comment` ORDER BY id";
    	$comment_s = $db->doResultList2();
    	//var_dump($comment_s);
    	$successword = '';
    	foreach ($comment_arry as $key2=>$item2){
    	    $j = 0;
    	    foreach ($comment_s as $key1 => $item1){
    	        similar_text($item2,$item1['comment'],$percent);
    	        if($percent>80) {
    	            /* $similar_text_array[$key2]['c'][$key1]['id']=$item1['id'];
    	             $similar_text_array[$key2]['c'][$key1]['comment']=$item1['comment'];
    	            $similar_text_array[$key2]['c'][$key1]['percent']=number_format($percent,2); */
    	            $j++;
    	        }
    	    }
    	    if($j==0){
    	       echo $db->sql="INSERT INTO comment(`comment`,`cates`) VALUES ('{$item2}','{$cate_i}')";
    	        $db->doExecute();
    	        $successword .= $item2."添加成功！！！<br />";
    	    }else{
    	       
    	        $successword .= $item2."添加失败！！！有{$j}条数据相似度大于80%<br />";
    	        
    	    }
    	}
	}
	/* if($act=='insert'){
	    $values = '';
	    $success_num = 0;
	    foreach ($_POST['comments1'] as $key5=>$item5){
	        if(count($_POST['commentSel'])>0){
	            foreach ($_POST['commentSel'] as $key6=>$item6){
	                if($item6==$key5){
	                    $values .= "('".$item5."','".$cate_i."'),";
	                    $success_num++;
	                }
	            }
	        }
	    }
    	$db->sql="INSERT INTO comment(`comment`,`cates`) VALUES".rtrim($values,',');
    	$db->doExecute();
    	$comments='';
    	$success=1; 
	} */
}
//分类
$db->sql="SELECT * FROM category ORDER BY sort ASC";
$cates = $db->doResultList2();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo APPLICATION;?></title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/main.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />
<style type="">
	span{width: 85px;font-weight: bold;display: block;float: left;}
</style>
<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function($) {
	$("form").submit(function(){
		if(!$("#comments").val()){
			alert("不能为空！");
			return false;
		}
	});
	$(".check-all1").click(function(){
		//alert(11);
		$(this).parents('table').find(".commentSel").attr('checked', $(this).is(':checked'));
	});
});
</script>
<!-- jQuery Configuration -->
<script type="text/javascript"
	src="resources/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>

</head>

<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		
		<div id="main-content">
			<!-- Page Head -->
			<h2>欢迎使用<?php echo APPLICATION;?>管理后台</h2>
			<p id="page-intro">用户<?php if($act=="edit") echo "修改";else echo "添加";?></p>

			<div class="clear"></div>
			<!-- End .clear -->

			<div class="content-box">
				<!-- Start Content Box -->

				<div class="content-box-header">

					<h3>用户<?php if($act=="edit") echo "修改";else echo "添加";?></h3>

					<div class="clear"></div>

				</div>
				<!-- End .content-box-header -->

				<div class="content-box-content">
				
                <?php if(1==2 && count($similar_text_array)>0):?>
                <form action="?act=insert" method="post">
				    <div class="tab-content default-tab" id="tab1">
						<!-- This is the target div. id must match the href of this div's tab -->
						<table>
							<thead>
								<tr>
									<th><input class="check-all1" type="checkbox" value="-1">要新增的评论</th>
									<th>存在评论ID</th><th>已存在的评论</th><th>相似度</th>
								</tr>
							</thead>

							<tbody>
							<?php foreach ($similar_text_array as $key=>$item):if(count($item['c'])>0):?>
							    <?php $i=0;foreach ($item['c'] as $key2=>$item2):?>
								<tr>
									<?php if($i==0):?>
									<td rowspan="<?php echo count($item['c']);?>">
									    <input class="commentSel" type="checkbox" name="commentSel[]" value="<?php echo $key;?>"/>
									    <input type="hidden" name="comments1[]" value="<?php echo $item['p'];?>" />
									    <?php echo $item['p'];?>
									    </td>
									<?php endif;?>
									<td><?php echo $item2['id']?></td>
									<td><?php echo $item2['comment'];?></td>
									<td><?php echo $item2['percent'].'%';?></td>
								</tr>
								<?php $i++;endforeach;?>
							<?php endif;endforeach;?>
							    <tr><td colspan="4"><hr /></td></tr>
							    <tr><td colspan="4">
							        <?php foreach ($cates as $keyC=>$itemC):?>
							        <input type="checkbox" name="cates[]" value="<?php echo $itemC['id'];?>" checked="checked"/><?php echo $itemC['cate'];?>&nbsp;&nbsp;&nbsp;
							        <?php endforeach;?>
							        </td></tr>
							</tbody>
							<tfoot>
								<tr><td>
								<input type="hidden" name="comments" value="<?php echo $comments;?>"/>
									<button type="submit" class="button">添加</button>
									</td>
								    <td colspan="3"></td>
								</tr>
							</tfoot>
						</table>
				    </div>
			    </form>
			    <hr /><hr /><hr />
				<?php endif;?>  
				<!-- Start Notifications -->
				<div class="notification information png_bg">
					<a href="#" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
					<div>
						注意添加时，可以换行，批量添加多个评论！如：<br /><br />好划算呀！不入手简直亏了！<br />暖暖的感觉~靠它过冬啦~<br />...<br />...<br />...
					</div>
				</div>
				<?php if($_POST):?>
				<div class="notification success png_bg">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
						<?php echo $successword;?>
					</div>
				</div>
				<?php endif;?>
				<?php if($error==1 || $error==2 || $error==3):?>
				<div class="notification error png_bg">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
					<?php if($error == 1) echo "用户已经存在";elseif($error==2) echo "密码不一致！";elseif($error==3) echo "出错，请刷新后重新操作！";?>
					</div>
				</div>
				<?php endif;?>
				<!-- End Notifications -->
					<div class="tab-content default-tab" id="tab1">
						<form action="?act=postshenhe" method="post">
							<fieldset>
								<!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
								<p>
									<span>评论:</span> 
									<textarea rows="10" name="comments" id="comments"><?php echo $comments;?></textarea>
								<p>
									<input type="hidden" name="act" value="<?php echo $act;?>"/>
									<input class="button" type="submit" value="<?php if($act=="edit") echo "修改";else echo "提交审核";?>" />
									<input class="button" type="reset" value="清空" />
								</p>

							</fieldset>

							<div class="clear"></div>
							<?php foreach ($cates as $keyC=>$itemC):?>
							    <input type="checkbox" name="cates[]" value="<?php echo $itemC['id'];?>" checked="checked"/><?php echo $itemC['cate'];?>&nbsp;&nbsp;&nbsp;
							<?php endforeach;?>
							<!-- End .clear -->

						</form>

					</div>
					<!-- End #tab2 -->

				</div>
				<!-- End .content-box-content -->

			</div>
			<!-- End .content-box -->

			<div class="clear"></div>

			<div id="footer">
				<small> <!-- Remove this notice or replace it with whatever you want -->
					&#169; Copyright 2009 Your Company | Powered by <a
					href="http://themeforest.net/item/simpla-admin-flexible-user-friendly-admin-skin/46073">Simpla
						Admin</a> | <a href="#">Top</a>
				</small>
			</div>
			<!-- End #footer -->

		</div>
		<!-- End #main-content -->

	</div>
</body>


<!-- Download From www.exet.tk-->
</html>
